﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.ScheduleJob.SPI;

namespace T.FAS.Runtime.ScheduleJob.Engine
{
    public class UserDefineJobEngine : IScheduleJobImpEngineProxy, IScheduleJobExecuteHandler, IScheduleJobDataResultBuilder
    {
        public void AfterExecute(ScheduleJobExecContext execContext, TResult result)
        {

        }

        public void BeforeExecute(ScheduleJobExecContext execContext)
        {

        }

        public TResult BuildScheduleJobDataResult(ScheduleJobExecContext context, object dataResult)
        {
            return new TResult();
        }

        public object Execute(ScheduleJobExecContext context)
        {
            if (context == null)
                return null;
            var tType = Type.GetType(context.ScheduleJobMetaData.JobContent);
            var executor = Activator.CreateInstance(tType) as IScheduleJobExecutor;
            return executor.Execute(context);
        }

        public void ExecuteError(ScheduleJobExecContext execContext, Exception exception)
        {
        }
    }
}
